﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace OmniKits.Windows.Interop
{
    public static class DwmApi
    {
        public static int SupportedLevel { get; private set; }

        public const string DllName = "dwmapi.dll";

        static DwmApi()
        {
            var os = Environment.OSVersion;
            if (os.Platform != PlatformID.Win32NT)
            {
                SupportedLevel = -1; // not NT
                return;
            }
            var ver = os.Version;
            if (ver.Major < 6 || ver.Minor < 0) // pre-vista windows
                return;

            if (ver.Major >= 10) // Windows 10
                SupportedLevel = 10;
            else if (ver.Major > 6) // WTF!?
                SupportedLevel = 4;
            else
            {
                switch (ver.Minor)
                {
                    case 0:
                        SupportedLevel = 1; // vista
                        break;
                    case 1:
                        SupportedLevel = 2; // 7
                        break;
                    case 2:
                        SupportedLevel = 3; // 8
                        break;
                    default:
                        SupportedLevel = 4; // 8.1 and so on
                        break;
                }
            }
        }

        [DllImport(DllName, PreserveSig = false)]
        public static extern bool DwmIsCompositionEnabled();

        [DllImport(DllName, PreserveSig = false)]
        public static extern void DwmExtendFrameIntoClientArea(IntPtr handle, ref Margins margins);
    }
}
